<!-- 教育信息 -->
<template>
	<view class="education">
		<view class="flex alignCenter tip">
			<view class="flex alignCenter">
				<image src="https://image.alhelp.net/uploads/20231104/f5a50463b8dd7a1b1ea25f211c8ffd65.png" mode="widthFix"></image>
				<view class="font14 color999">首先填写教育信息喔！</view>
			</view>
			
			<view class="font14 bold num"><text class="colorMain font18">1</text>/3</view>
		</view>
		
		<view class="year">
			<uni-mdlist :listData="itemArr" @clickItem="clickItem"></uni-mdlist>
		</view>
		<view class="schoolAndMajor">
			<uni-mdlist :listData="otherArr" @clickItem="clickItem"></uni-mdlist>
		</view>
		<view class="cardItem">
			<view class="font14 flex alignCenter"><text class="colorRed">*</text><text>证件证明</text></view>
			<view class="font14 upload">
				<view class="upload-url flex alignCenter">
					<uni-singleimg :fileUrl="imgUrl" v-if="imgUrl" @delPic="delPic"></uni-singleimg>
					<view class="bold uploadCommon colorccc" @click="uploadFileClick">+</view>
				</view>
				<view class="color999 normalTip">在校生可上传学生证,刚录取的可上传录取通知书,已毕业的可上传毕业证、结业证等</view>
				<view class="colorMain importantTip">认证后会获得标识别，更容易得到信任喔！</view>
			</view>
		</view>
		<!-- <view class="cardItem">
			<view class="font14 flex alignCenter"><text>简介</text></view>
			<view class="font14">
				<textarea class="introduction font14" maxlength="100" placeholder="简介内容(100个字符以内)" v-model.trim="introduction" cols="30" rows="10"></textarea>
			</view>
		</view> -->
		<view class="fixedBottomBtn flex alignCenter" v-if="(!showYear&&!showProvince&&!showCollege)" @click="sureClick">
			下一步
			<view class="icons flex alignCenter"><image src="../../../static/rightIcon.png" mode="widthFix"></image></view>  
		</view>
		<!-- 选择年份 -->
		<uni-yearpicker :showYear="showYear" @cancel="cancel" @sureYear="sureYear"></uni-yearpicker>
		<!-- 选择学校 -->
		<uni-chooseschool v-if="showProvince" :showProvince="showProvince" @schoolSuccess="schoolSuccess" @cancelProvince="cancelProvince"></uni-chooseschool>
		<!-- 选择专业 -->
		<uni-choosemajor v-if="showCollege" :school="otherArr[0].school" :showCollege="showCollege" @majorSuccess="majorSuccess" @cancelColl="cancelColl"></uni-choosemajor>
	</view>
</template>

<script>
	import { addEducation,eduDetail,editEdu,getEdu } from "@/api/mine.js"
	import { uploadFile,chooseImg,previewImg} from "@/utils/common.js"
	import uniYearpicker from "@/pages/send/components/uni-yearpicker/uni-yearpicker.vue"
	import uniChoosemajor from "@/pages/send/components/uni-choosemajor/uni-choosemajor.vue"
	export default {
		components:{
			uniYearpicker,
			uniChoosemajor
		},
		data() {
			return {
				showYear:false,
				showProvince:false,
				showCollege:false,
				info: {},
				itemArr:[{
					title:'入学年份',
					icon:'/static/image/setting/cal.png',
					val:''
				}],
				otherArr:[{
					title:'研究生大学',
					icon:'/static/image/setting/major.png',
					school:'',
					val:''
				},{
					title:'研究生专业',
					icon:'/static/image/setting/major.png',
					college:'',
					major:'',
					val:''
				}],
				imageValue:[],
				imgUrl:'',
				// fromPage:'',
				editId:'',
				introduction:'',
				backDelta: '',//返回页面数
				
			};
		},
		onLoad(option) {
			// this.fromPage=option.from?option.from:''
			if(option.backDelta){
				this.backDelta = option.backDelta;
			}
			this.getDetail();
		},
		methods:{
			// 详情（编辑时调用）
			getDetail(){
				getEdu({diploma: '2'}).then(res=>{
					if(res.code == 100000 && res.data){
						console.log('信息',res);
						this.info = res.data;
						this.editId = res.data.id;
						// 数据回显
						this.itemArr[0].val=res.data.graduationYear
						this.otherArr[0].school={
							title:res.data.schoolName,
							schoolCode:res.data.schoolCode
						}
						this.otherArr[0].val=res.data.schoolName
						this.otherArr[1].major={
							title:res.data.majorName,
							majorCode:res.data.majorCode
						}
						this.otherArr[1].val = res.data.majorName
						this.imgUrl = res.data.imgUrl
					}
				})
			},
			// 列表功能的点击事件
			clickItem(item){
				if(item.title=='入学年份'){
					this.showYear = true;
					console.log(22222,item);
					return
				}else if(item.title=='研究生大学'){
					this.showProvince = true;
					return
				}else if(item.title=='研究生专业'){
					if(!this.otherArr[0].school){
						uni.showToast({
							icon:'none',
							title:'请先选择学校'
						})
						return
					}
					this.showCollege = true
					return
				}
			},
			uploadFileClick(){
				chooseImg(1).then((files)=>{
					console.log(11111,files);
					uploadFile(files).then((successFile)=>{
						console.log('文件',successFile)
						this.imgUrl = successFile.url
					})
				})
			},
			// 预览图片
			showBigPic(){
				previewImg([this.imgUrl])
			},
			delPic(){
				this.imgUrl=''
			},
			cancel(){
				this.showYear=false
			},
			sureYear(year){
				this.itemArr[0].val=year
				this.showYear=false
			},
			cancelProvince(){
				this.showProvince=false
			},
			cancelColl(){
				this.showCollege=false
			},
			// 选择学校后的确定回调事件
			schoolSuccess(item){
				this.showProvince=false
				this.otherArr.forEach((val)=>{
					if(val.title=='研究生大学'){
						val.val=item.school.title
						val.school=item.school
					}else if(val.title=='研究生专业'){
						val.val=''
						val.college=''
						val.major=''
					}
				})
			},
			majorSuccess(item){
				this.showCollege=false
				this.otherArr.forEach((val)=>{
					if(val.title=='研究生专业'){
						val.val=item.major.title
						val.college=item.college
						val.major=item.major
					}
				})
			},
			sureClick(){
				let canNext = true;
				this.itemArr.forEach((item)=>{
					if(!item.val){
						uni.showToast({
							title:`请选择${item.title}`,
							icon:'none'
						})
						canNext=false
						return
					}
				})
				this.otherArr.forEach((item)=>{
					if(!item.val){
						uni.showToast({
							title:`请选择${item.title}`,
							icon:'none'
						})
						canNext=false
						return
					}
				})
				if(!this.imgUrl){
					uni.showToast({
						title:'请上传学生证/录取通知书/毕业证/结业证',
						icon:'none'
					})
					return
				}
				if(canNext){
					let param={
						diploma:2,//1本科；2硕士研究生（学长学姐卡片上显示的学历是这个）；3博士研究生
						graduationYear:this.itemArr[0].val,//毕业年份
						schoolCode:this.otherArr[0].school.schoolCode,
						schoolName:this.otherArr[0].school.title,
						majorCode:this.otherArr[1].major.majorCode,
						majorName:this.otherArr[1].major.title,
						imgUrl:this.imgUrl,
						introduce: this.info.introduce,
						tags: this.info.tags,
						fileUrls: this.info.fileUrls,
					}
					if(this.editId){
						param.id = this.editId;
					}	
					uni.navigateTo({
						url:`/pages/send/lookFor/postgraduate/enrollment/advantage?param=${JSON.stringify(param)}&backDelta=${this.backDelta}`
					})
				}
			}
		}
	}
</script>
<style lang="scss">
page{
	background-color:$pageBgColor;
}
</style>
<style lang="scss" scoped>
.education{
	padding: 0 30rpx 120rpx;
	box-sizing: border-box;
	.tip{
		padding: 60rpx 44rpx 40rpx 44rpx;
		box-sizing: border-box;
		justify-content: space-between;
		// margin:0 0 60rpx 0;
		image{
			width:92rpx;
			height:84rpx;
			margin:0 20rpx 0 0;
		}
		.num{
			margin-left: 20rpx;
		}
	}
}
.year{
	margin:0rpx 0 30rpx;
}
.cardItem{
	background: #fff;
	border-radius: 10rpx;
	padding: 30rpx;
	box-sizing: border-box;
	margin: 30rpx 0;
	.upload{
		margin:30rpx 0 0;
	}
	.upload-url{
		justify-content: center;
		margin-bottom: 20rpx;
	}
	.title{
		flex-shrink: 0;
	}
	input{
		width:100%;
		text-align: right;
	}
	textarea{
		margin:30rpx 0 0;
		padding: 15rpx;
		background: $pageBgColor;
		width: 100%;
		box-sizing: border-box;
		border-radius: 10rpx;
	}
}

.fixedBottomBtn{
	justify-content: center;
	
	.icons{
		margin-left: 36rpx;
		width: 32rpx;
		height: 32rpx;
		border-radius: 50%;
		background: #fff;
		text-align: center;
		image{
			width: 32rpx;
			height: 32rpx;
		}
	}
}
// .normalBtnStyle{
	// margin: 72rpx auto 0;
// }
</style>
